package cn.feuler.email8082.controller;

import cn.feuler.email8082.service.EmailService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/email")
public class EmailController {
    private final EmailService emailService;

    public EmailController(EmailService emailService) {
        this.emailService = emailService;
    }

    @GetMapping("/{email}/{code}")
    public Boolean SendEmail(@PathVariable String email, @PathVariable String code) {
        System.out.println("sending [" + code + "] to [" + email + "]");
        new Thread(() -> {
            emailService.send(email, code);
        }).start();
        return true;
    }
}
